<template>
	<div class="test">
		 <!--sql调试模态框-->
		<el-dialog title="SQL调试" :visible.sync="sqlTest">
			 <el-form :model="sqlForm"  ref="sqlForm" :label-position="labelPosition" class="demo-ruleForm">
					<span>输入设备上报数据</span>
					<el-form-item label="(JSON格式)" :label-width="formLabelWidth"  id="add" prop="attributes">
						<json></json>
					</el-form-item>
					<el-form-item label="结果" :label-width="formLabelWidth" >
						<el-input type="textarea" v-model="sqlForm.result"  style="width:90%"></el-input>
					</el-form-item>
			</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="sqlTest=false">取 消</el-button>
			<el-button type="primary"  @click="submit('sqlForm')">确 定</el-button>
		</div>
		</el-dialog>
	</div>
</template>
<script>
import $ from 'jquery';
import bus from '../../eventBus.js'
import json from '../../components/Json.vue';
export default{
	name:'sqlTest',
	components:{ json },
	data(){
		return{
			labelPosition:'left',
			sqlTest:false,
			erry:true,
			formLabelWidth:'120px',
			sqlForm:{
				shuju:'',
				result:''
			},
		}
	},
	methods:{
		submit(formName){
			let err=window.yeZheng();
			if(err){
				let para=$('#add').find('textarea').val();
				this.sqlForm.shuju=para;
				console.log(this.sqlForm.shuju);
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.sqlTest=false;
						window.zfLoad("code");
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}else{
				this.$message({
					message: 'JSON格式不正确',
					type: 'warning'
				});
			}
		}
	},
	mounted(){
		var self=this;
		bus.$on("sqlTest",function (msg) {
			self.sqlTest=msg;
		});
	}
}

</script>


<style>


</style>